package com.glela.goods.service.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glela.goods.mapper.GoodsNavigateMapper;
import com.glela.goods.model.GoodsNavigate;
import com.glela.goods.service.GoodsNavigateService;

@Service
public class GoodsNavigateServiceImpl implements GoodsNavigateService {
	@Autowired
	private GoodsNavigateMapper goodsNavigateMapper;

	@Override
	public Map<Long, List<GoodsNavigate>> queryByGoodsIds(Collection<Long> goodsIds) {
		Map<Long, List<GoodsNavigate>> goodsNavigateMap = new HashMap<>();
		if (CollectionUtils.isNotEmpty(goodsIds)) {
			List<GoodsNavigate> selectGoodImgByGoodIdList = goodsNavigateMapper.selectGoodImgByGoodIdList(goodsIds);
			for (GoodsNavigate goodsNavigate : selectGoodImgByGoodIdList) {
				if (goodsNavigateMap.get(goodsNavigate.getGoodId()) == null) {
					goodsNavigateMap.put(goodsNavigate.getGoodId(), new LinkedList<GoodsNavigate>());
				}
				goodsNavigateMap.get(goodsNavigate.getGoodId()).add(goodsNavigate);
			}
		}
		return goodsNavigateMap;
	}

}
